package top.onedream.buildsmallsoftware.model.user

import org.hibernate.annotations.DynamicInsert
import org.hibernate.annotations.DynamicUpdate
import org.springframework.data.jpa.domain.AbstractAuditable
import javax.persistence.*


/**
 * 用户
 * @author zhangkein
 * @date 2023/05/21
 * @constructor 创建[User]
 * @param [id] id
 * @param [username] 用户名
 * @param [nickname] 昵称
 * @param [role] 角色
 */
@Entity
@DynamicUpdate
@DynamicInsert
@Table(name = "user")
data class User(
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long? = null,

    @Column(
        name = "username",
        length = 20,
        unique = true,
        nullable = false
    )
    var username: String? = null,

    @Column(
        name = "password",
        nullable = false,
        columnDefinition = "varchar(64) default '123456'"
    )
    var password: String? = null,

    @Column(
        name = "salt",
        length = 32
    )
    var salt: String? = null,

    @Column(
        name = "nickname",
        length = 20,
        nullable = true
    )
    var nickname: String? = null,

    @Column(
        name = "age",
    )
    var age: Int? = null,

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(
        name = "role_id",
        referencedColumnName = "id",
        nullable = false
    )
    var role: Role? = null
)